package csu.webcourse.mypetstore.persistence.impl;

import csu.webcourse.mypetstore.persistence.DBUtil;
import csu.webcourse.mypetstore.persistence.LogDao;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class LogDaoImpl implements LogDao {

    private static final String INSERT_LOG_STRING = "INSERT INTO log (USERID, LOGINFO) VALUES (?, ?)";//log表中的userid和logInfo字段

    @Override
    public void insertLog(String username, String logInfo) {
        try {
            Connection connection = DBUtil.getConnection();
            PreparedStatement preparedStatement = connection.prepareStatement(INSERT_LOG_STRING);
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, logInfo);

            preparedStatement.executeUpdate();
            DBUtil.closePreparedStatement(preparedStatement);
            DBUtil.closeConnection(connection);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
